package com.jyx.refactor.beginner;

import java.util.Enumeration;
import java.util.Vector;

import com.jyx.refactor.beginner.service.Price;
import com.jyx.util.print.PrintUtil;

/**
 * 客户
 * author 		jyx
 * email 		jyxsuper@163.com
 * description: Customer
 * Company: 	myzczk
 * datetime: 	2017年9月19日 上午10:31:35
 */
public class Customer {

	private String _name;
	private Vector _rentals = new Vector();
	
	/**
	 * 实际租借过程
	 * @return
	 */
	public String statement(){
		Enumeration rentals = _rentals.elements();
		String result = "Rental Record for " + get_name() + "\n";
		
		while(rentals.hasMoreElements()){
			Rental each = (Rental)rentals.nextElement();// 获得一次租借记录
			// 显示租金数字
			result += "\t" + each.get_movie().get_title() + "\t" + String.valueOf(each.calcAmount()) + "\n";
		}
		
		// 打印租赁金额和客户积分
		result += "Amount owed is "+ String.valueOf(calcTotalAmount()) + "\n";
		result += "You earned " + String.valueOf(calcTotalIntegral()) + " frequent renter points";
		PrintUtil.println(result);
		return result;
	}
	
	/**
	 * 计算客户总积分
	 * @return
	 */
	public int calcTotalIntegral(){
		int totalIntegral = 0;
		Enumeration rentals = _rentals.elements();
		while (rentals.hasMoreElements()) {
			Rental rental = (Rental) rentals.nextElement();
			totalIntegral += rental.calcIntegral();
		}
		return totalIntegral;
	}
	
	/**
	 * 计算个人租赁总金额
	 * @return
	 */
	public double calcTotalAmount(){
		double totalAmount = 0;
		Enumeration rentals = _rentals.elements();
		while (rentals.hasMoreElements()) {
			Rental rental = (Rental) rentals.nextElement();
			totalAmount += rental.calcAmount();
		}
		return totalAmount;
	}
	
	/**
	 * 添加租赁信息
	 * @param rental
	 */
	public void addRental(Rental rental){
		_rentals.addElement(rental);
	}
	
	
	public Customer(String _name) {
		super();
		this._name = _name;
	}


	public String get_name() {
		return _name;
	}


	public void set_name(String _name) {
		this._name = _name;
	}
	
	
}
